package com.lazily.try_;


/**
 * @Author: GZQ
 * @date: 2025/2/23 15:12
 * @description: 练习3
 */

public class TryCatchExercise03 {

	// 程序入口
	public static void main(String[] args) {
		System.out.println(method()); // 4
	}

	public static int method() {
		int i = 1; // i = 1
		try {
			i++; // i = 2
			String[] names = new String[3];
			if (names[1].equals("tom")) {
				System.out.println(names[1]);
			} else {
				names[3] = "jack";
			}
			return 1;
		} catch (ArrayIndexOutOfBoundsException e) {
			return 2;
		} catch (NullPointerException e) { // 捕获
			return ++i; // i = 3 => 保存临时变量 temp = 3;
		} finally { // 必须执行
			++i; // i = 4;
			System.out.println("i=" + i); // i = 4;
		}
	}
}